import json

import requests

from common.config import getconf

env='test'

class GetToken():
    def __cookies__(self):
        '''获取token'''
        base_url = getconf('test', "data_url")
        url = base_url + "buorg/v1/session/login"
        data = {
            "account": 'csyyzx01',
            "password": 'a12345678'
        }
        headersbus={"Content-Type": "application/json;charset=UTF-8","application":"cms"}
        r = requests.post(url, json=data, headers=headersbus)
        token = r.json()['token']
        return token

class GameBoard(GetToken):
    def __init__(self):
        self.headers = {
            'Content-Type':'application/json;charset=UTF-8',
            'application':'cms',
            'token':GetToken().__cookies__(),
        }

    def activityList(self,env):
        base_url = getconf(env, "data_url")
        url = base_url + "triton/dashboard/game/activityList"
        data={"branchId":"8893"}
        r=requests.post(url=url,data=json.dumps(data),headers=self.headers)
        print('活动列表')
        return r.json()

    def partakeAnaly(self,env):
        base_url = getconf(env, "data_url")
        url = base_url + "triton/dashboard/game/partakeAnaly"
        data={"branchId":"8893","activityId":205,"queryFlag":0}
        r=requests.post(url=url,data=json.dumps(data),headers=self.headers)
        print('参与情况',r.json())
        return r.json()

    def visitCurveList(self,env,flag):
        base_url = getconf(env, "data_url")
        url = base_url + "triton/dashboard/game/visitCurveList"
        data={"branchId":"8893","activityId":205,"queryFlag":int(flag)}
        r=requests.post(url=url,data=json.dumps(data),headers=self.headers)
        print('总访问次数')
        return r.json()

    def partakeCurveList(self,env,flag):
        base_url = getconf(env, "data_url")
        url = base_url + "triton/dashboard/game/partakeCurveList"
        data={"branchId":"8893","activityId":205,"queryFlag":int(flag)}
        r=requests.post(url=url,data=json.dumps(data),headers=self.headers)
        print('总参与次数')
        return r.json()

    def completeCurveList(self,env,flag):
        base_url = getconf(env, "data_url")
        url = base_url + "triton/dashboard/game/completeCurveList"
        data={"branchId":"8893","activityId":205,"queryFlag":int(flag)}
        r=requests.post(url=url,data=json.dumps(data),headers=self.headers)
        print('总完成次数')
        return r.json()

    def userFunnelAnaly(self,env):
        base_url = getconf(env, "data_url")
        url = base_url + "triton/dashboard/game/userFunnelAnaly"
        data={"branchId":"8893","activityId":205,"queryFlag":0}
        r=requests.post(url=url,data=json.dumps(data),headers=self.headers)
        print('用户分析',r.json())
        return r.json()

    def userShareByPage(self,env):
        base_url = getconf(env, "data_url")
        url = base_url + "triton/dashboard/game/userShareByPage"
        data={"branchId":"8893","activityId":205,"current":1,"size":10}
        r=requests.post(url=url,data=json.dumps(data),headers=self.headers)
        print('用户分享分页')
        return r.json()

    def userShareTrend(self,env):
        base_url = getconf(env, "data_url")
        url = base_url + "triton/dashboard/game/userShareTrend"
        data={"branchId":"8893","activityId":205,"queryFlag":0}
        r=requests.post(url=url,data=json.dumps(data),headers=self.headers)
        print('用户分享趋势')
        return r.json()

    def fansCurveList(self, env, flag):
        base_url = getconf(env, "data_url")
        url = base_url + "triton/dashboard/game/fansCurveList"
        data = {"branchId": "8893", "activityId": 205, "queryFlag": int(flag)}
        r = requests.post(url=url, data=json.dumps(data), headers=self.headers)
        print('粉丝趋势')
        return r.json()

    def memberCurveList(self, env, flag):
        base_url = getconf(env, "data_url")
        url = base_url + "triton/dashboard/game/memberCurveList"
        data = {"branchId": "8893", "activityId": 205, "queryFlag": int(flag)}
        r = requests.post(url=url, data=json.dumps(data), headers=self.headers)
        print('会员趋势')
        return r.json()

    def prizeTypeAnalysis(self, env, flag):
        base_url = getconf(env, "data_url")
        url = base_url + "triton/dashboard/game/prizeTypeAnalysis"
        data = {"activityId":205,"prizeType":flag,"startTime":"2019-12-26","endTime":"2020-01-25"}
        r = requests.post(url=url, data=json.dumps(data), headers=self.headers)
        print('奖品')
        return r.json()


#a=GameBoard()
#a.prizeTypeAnalysis('test','1')
